package com.example.smartplay.controller;


import com.example.smartplay.entity.Inform;
import com.example.smartplay.entity.Result;
import com.example.smartplay.service.InformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 
 * @since 2024-07-26
 */
@RestController
@RequestMapping("/inform")
public class InformController {
    @Autowired
    private InformService informService;

    //查询所有公告
    @GetMapping
    public Result list() {
        List<Inform> list = informService.list();
        return Result.success(list);
    }



 //分页查询公告
    @GetMapping("/getinform/{pageNum}/{pageSize}")
    public Result getinform(
            @RequestParam(value = "keyword",required = false)  String keyword,
            @PathVariable("pageNum") Integer pageNum,
            @PathVariable("pageSize") Integer pageSize
    ) {
        return informService.getinform(keyword,pageNum, pageSize);
    }

    //新增或者修改公告
    @PostMapping("/saveOrUpdate")
    public Result saveOrUpdate(@RequestBody Inform inform) {
        informService.saveOrUpdate(inform);
        return Result.success();
    }
    //批量删除公告
    @DeleteMapping("{ids}")
    public Result delete(@PathVariable List<Integer> ids) {
        informService.removeByIds(ids);
        return Result.success();
    }

}
